package server;

import java.io.IOException;
import java.io.ObjectInputStream;
//import java.io.ObjectOutputStream;
import java.net.Socket;

import common.LoginMessage;
import common.User;

public class ThreadedPISTServer implements Runnable {
    Socket socket;
    Object message;

    ThreadedPISTServer(Socket s) {
        this.socket = s;
    }

    public void run() {
        UserCatalog userCatal = new UserCatalog();

        try {
//            ObjectOutputStream out = new ObjectOutputStream(socket
//                    .getOutputStream());
            ObjectInputStream in = new ObjectInputStream(socket
                    .getInputStream());

            message = in.readObject();
            if (message instanceof LoginMessage)
                userCatal.add((User) ((LoginMessage) message).getContent());
            // TODO Falta os outros.

            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
